package com.ceair.flight.refund.util;

import com.ceair.flight.refund.dto.appmoblie.RefundApplyDto;
import com.ceair.flight.refund.dto.external.RefundApply;
import org.springframework.beans.BeanUtils;

import java.util.Objects;

/**
 * RefundApply转换器
 *
 * @author: chenglongyi
 **/
public class RefundApplyConverUtil {
    /**
     * RefundApply转为RefundApplyDto
     *
     * @param refundApply
     * @return
     */
    public static RefundApplyDto refundApplyConverter(RefundApply refundApply) {
        Objects.requireNonNull(refundApply);
        RefundApplyDto dto = new RefundApplyDto();
        BeanUtils.copyProperties(refundApply, dto);
        dto.setIsVoluntary(refundApply.isVoluntary() ? 1 : 0);
        return dto;
    }

    /**
     * RefundApplyDto转换为RefundApply
     *
     * @param dto
     * @return
     */
    public static RefundApply refundApplyConverter(RefundApplyDto dto) {
        Objects.requireNonNull(dto);
        RefundApply refundApply = new RefundApply();
        BeanUtils.copyProperties(dto, refundApply);
        refundApply.setVoluntary(dto.getIsVoluntary() == 1 ? true : false);
        return refundApply;
    }
}
